var deviceReady = false;

/**
 * Function called when page has finished loading.
 */
function initScringo() {
	document.addEventListener("deviceready", function() {
		scringo.initWithAppId("gmXBTxfDAudnXfngp2n168qGU6DcNV6F", function() {
			console.log("Done Init Scringo");
		}, function(errorMessage) {
			alert("Scringo failed to start: " + errorMessage);
		});
		scringo.setTestMode(1);
		deviceReady = true;
		//console.log("Device=" + device.platform + " " + device.version);
	}, false);
	window
			.setTimeout(
					function() {
						if (!deviceReady) {
							alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
						}
					}, 1000);
}

function addScringo() {
	scringo.addSidebar(1);
}

function openScringo() {
	scringo.isSidebarOpen(function(isOpen) {
		if (!isOpen) {
			scringo.openSidebar();
		}
	});
}

function openMenu() {
	scringo.openMenu(function(errorMessage) {
		alert("Failed opening Scringo Menu: " + errorMessage);
	}, 0, 0);
}

function preloadQuizzes() {
	scringo.preloadQuizzes(function() {
		alert("Quizzes were preloaded");
	});
}

function openQuiz() {
	scringo.openQuiz(1, 1);
}

function preloadChatRooms() {
	scringo.preloadChatRooms(function() {
		alert("Chat Rooms were preloaded");
	});
}

function openChatRooms() {
	scringo.openChatRooms(1, 1);
}

function openMyProfile() {
	scringo.openMyProfile(1, 1);
}

function postToFeed() {
	scringo.postToFeed("Testing Phonegap client", function(errorMessage) {
		alert(errorMessage);
	});
}

function getInboxBadgeNumber() {
	scringo.getFeatureBadgeNumber(1, function(badge) {
		alert("Inbox badge is " + badge);
	}, function(errorMessage) {
		alert(errorMessage);
	});
}

function openChatWithTestUser() {
	scringo.openChatWithUser("testUser2", 1, 1, function(errorMessage) {
		alert(errorMessage);
	});
}
 

function registerScringoUser(email,password,login,step) {
	scringo.registerUser(email,password,login, function(scringoId) {
		//TODO dar de alta en quickblox  y pasar step tb
		registerQBUser(email,password,login,scringoId,step);
	}, function(errorMessage) {
		alert(errorMessage);
	});
}

function getCurrentScringoUser() {
	scringo.getCurrentScringoUser( function(badge) {
		console.log("getCurrentScringoUser  " + badge);
	}, function(errorMessage) {
		console.log("ERROR getCurrentScringoUser "+errorMessage);
	});
}